<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <form class="layui-form" action="" lay-filter="bicycleForm">

        <div class="layui-form-item" aria-disabled="true">
            <label class="layui-form-label required">订单编号</label>
            <div class="layui-input-block">
                <input type="text" name="orderId" lay-verify="required" lay-reqtext="名称不能为空" 
                placeholder="请输入订单" value="" class="layui-input" aria-readonly="true">
            </div>
        </div>

        
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">订单开始时间</label>
            <div class="layui-input-block">
                <input type="datetime" name="bicycleOrderStart" id="dateStart" lay-verify="datetime"  placeholder="yyyy-MM-dd HH:mm:ss" placeholder="请输入订单开始时间" 
                       autocomplete="off" class="layui-input" width="180px" height="60px">
            </div>
        </div>
    
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">订单结束时间</label>
            <div class="layui-input-block">
                <input type="datetime" name="bicycleOrderEnd" id="dateEnd" lay-verify="datetime" placeholder="yyyy-MM-dd HH:mm:ss" placeholder="请输入订单结束时间" 
                       autocomplete="off" class="layui-input"  width="180px" height="60px">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">租借时长</label>
            <div class="layui-input-block">
                <input name="rentTime" class="layui-input" placeholder="请输入租借时长"></input>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">单价</label>
            <div class="layui-input-block">
                <input name="price" class="layui-input" placeholder="请输入单价"></input>
            </div>
        </div>
    
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">支付金额</label>
            <div class="layui-input-block">
                <input name="amountMoney" class="layui-input" placeholder="请输入支付金额"></input>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','element','upload'], function () {
        var form = layui.form,
        layer = layui.layer,
            element = layui.element,
            upload = layui.upload,
            $ = layui.jquery,
            $ = layui.$,
              // 日期组件
              laydate = layui.laydate;

            //日期   渲染上面 id 为 date 的 标签
            laydate.render({
                elem: '#dateStart',
                type:'datetime'
            });

            laydate.render({
                elem: '#dateEnd',
                type:'datetime'
            });

        // 从 localStorage 把数据取出来   并转成 js 对象
        //  JSON.parse("str")   把字符串转为 js 对象
        var data = JSON.parse(localStorage.getItem("bicycle"));

        //给表单数据赋值
        form.val("bicycleForm",{
            "orderId":data.orderId,
            "bicycleOrderStart":data.bicycleOrderStart,
            "bicycleOrderEnd":data.bicycleOrderEnd,
            "rentTime":data.rentTime,
            "price":data.price,
            "amountMoney":data.amountMoney
        });


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {

            //     // 关闭弹出层
            //     layer.close(index);

            //     var iframeIndex = parent.layer.getFrameIndex(window.name);
            //     parent.layer.close(iframeIndex);

            // });

            $.ajax({
                "url":"http://localhost:8080/bicycleOrder/bicycleOrderUpdate",
               // "headers":{"token":token},
                "data": data.field,
                // result 参数 表式后台响应的数据
                "success":function(result){
                    if(result.code == 200){

                        // 关闭 弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.msg("修改成功");
                        parent.layer.close(iframeIndex);

                    }else{
                        layer.msg(result.msg);
                    }
                },
                "dataType":"json"
            });

            return false;
        });

    });
</script>
</body>
</html>